/** Biorhythmix
 * @author Vitaliy Lagutin
 * @version 1.0
 */

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;

class Biogui extends JFrame {
	JComboBox jcbbd, jcbbm, jcbby;
	JLabel jlab1, jlab2, jlab3;
	JButton jbtn;
	PaintPanel pp;
	
	Calendar tmp = GregorianCalendar.getInstance();
	int ny = tmp.get(Calendar.YEAR);         // current year
	
	int bd, bm, by;	
	Integer[] bday = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
	Integer[] bmonth = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
	Integer[] byear = {ny, ny-1, ny-2, ny-3, ny-4, ny-5, ny-6, ny-7, ny-8, ny-9, ny-10, ny-11, ny-12, ny-13, ny-14, ny-15, ny-16, ny-17, ny-18, ny-19, ny-20, ny-21, ny-22, ny-23, ny-24, ny-25, ny-26, ny-27, ny-28, ny-29, ny-30, ny-31};
	int[] yPoint0 = new int[61]; int[] yPoint1 = new int[61]; int[] yPoint2 = new int[61]; int[] yPoint3 = new int[61];
	int[] xPoint = new int[61];

	Biogui() {
		JFrame jfrm = new JFrame("Biorhythmix");
		jfrm.getContentPane().setLayout(new FlowLayout()); // диспетчер компановки
		jfrm.setSize(640, 400);
		jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		jcbbd = new JComboBox(bday);
		jcbbm = new JComboBox(bmonth);
		jcbby = new JComboBox(byear);
		jlab1 = new JLabel();
		jlab2 = new JLabel();
		jlab3 = new JLabel();
		jbtn = new JButton("Start");
		pp = new PaintPanel(600, 300, this);
		
		jcbbd.setToolTipText("Выберите день");
		jcbbm.setToolTipText("Выберите месяц");
		jcbby.setToolTipText("Выберите год");
		jbtn.setToolTipText("Расчитать биоритмы");

		// Event processing JComboBox		
		jcbbd.addActionListener(new ActionListener() {
			public void actionPerformed (ActionEvent le) {
				bd = (Integer) jcbbd.getSelectedItem();
			}
		});		
		jcbbm.addActionListener(new ActionListener() {
			public void actionPerformed (ActionEvent le) {
				bm = (Integer) jcbbm.getSelectedItem();
			}
		});		
		jcbby.addActionListener(new ActionListener() {
			public void actionPerformed (ActionEvent le) {
				by = (Integer) jcbby.getSelectedItem();
			}
		});

		// Event processing JButton
		jbtn.addActionListener(new ActionListener() {
			public void actionPerformed (ActionEvent ae) {
				
				VerifDateofBirth v = new VerifDateofBirth(bd, bm, by);
				
				if (v.verif == true) {
					CalculDaysLife c = new CalculDaysLife(bd, bm, by);
					jlab2.setText("Число прожитих дней: " + c.daysum);
					
					for (byte i = 0; i < 61; i++) {
						xPoint[i] = c.xPoint[i];
						yPoint0[i] = c.yPoint0[i];
						yPoint1[i] = c.yPoint1[i];
						yPoint2[i] = c.yPoint2[i];
						//yPoint3[i] = c.yPoint3[i];
					}
					pp.repaint();
				}
			}
		});

		jlab1.setText("Дата рождения: ");
		jlab3.setText("Красный - физический | Зеленый - эмоциональный | Синий - интеллектуальный");
		jcbbd.setSelectedIndex(0);
		jcbbm.setSelectedIndex(0);
		jcbby.setSelectedIndex(0);
				
		// Добавление списков во фрейм
		jfrm.add(jlab1);
		jfrm.add(jcbbd);
		jfrm.add(jcbbm);
		jfrm.add(jcbby);
		jfrm.add(jbtn);
		jfrm.add(jlab2);
		jfrm.add(pp);
		jfrm.add(jlab3);

		// Отображение фрейма.
		jfrm.setVisible(true);
	}
}